/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.XmlDataBase;

import java.util.List;
import java.util.Set;

/**
 *
 * @author Viktor
 * Class medium represent a real medium stored in database
 */
public class Medium {
    
    private String id;
    private String type;
    private String name;
    
    // not required
    private Set<Movie> movies;
    
    // no parameter constructor
    public Medium(){}
    
    public Medium(String id,String name,String type,Set<Movie> movies){
        this.id = id;
        this.type = type;
        this.name = name;
        this.movies = movies;
    }
    
    /**
     * Add set of movies to medium
     * @param movies 
     */
    public void setMovies(Set<Movie> movies){
        if(movies == null)
            throw new NullPointerException("List of movies is null");
        this.movies = movies;
    }
    
    /**
     * Get movies from nedium
     * @return all medium's movies
     */
    public Set<Movie> getMovies(){
        return this.movies;
    }
    
    /**
     * Add movie to medium
     * throws IlleagalArgument, if movie is allready in medium
     * @param movie 
     */
    public void addMovie(Movie movie){
        if(movie == null)
            throw new NullPointerException("Movie to add is null");
        if(!movies.add(movie))
            throw new IllegalArgumentException("Movie is already in medium :" + movie);
    }
    
    /**
     * Remove movie from medium
     * Throws IllegalArgument if movie is not in medium
     * @param movie 
     */
    public void removeMovie(Movie movie){
        if(movie == null)
            throw new NullPointerException("Movie to remove is null");
        if(!this.movies.contains(movie))
            throw new IllegalArgumentException("Movie is not in medium's movies! : " + movie.toString());
        this.movies.remove(movie);
    }
    
    /**
     * Set type of medium
     * Trows Exception if type is nor in CD|DVD|HDD
     * @param type 
     */
    public void setType(String type){
        if(type == null || type.length() == 0)
            throw new NullPointerException("Medium type");
        if(type.compareTo("DVD") != 0 && type.compareTo("CD")!= 0 && type.compareTo("HDD") != 0)
            throw new IllegalArgumentException("wrong type parameter");
        this.type = type;
    }
    
    /**
     * 
     * @return type of medium 
     */
    public String getType(){
        return this.type;
    }
    
    /**
     * Set name of medium
     * @param name 
     */
    public void setName(String name){
        if(name == null || name.length() == 0)
            throw new NullPointerException("Medium name");
        this.name = name;
    }
    
    /**
     * 
     * @return medium's name 
     */
    public String getName(){
        return this.name;
    }
    
    /**
     * Set id of mendium
     * @param id
     * ID should be null, if medium is not in Database
     */
    public void setId(String id){
        if(id == null || id.length() == 0)
            throw new NullPointerException("Medium id");
        this.id = id;
    }
    
    /**
     * 
     * @return medium's id 
     */
    public String getId(){
        return this.id;
    }

    @Override
    public String toString() {
        return "Medium{" + "id=" + id + ", type=" + type + ", name=" + name + ", movies=" + movies + '}';
    }
    
}
